auto();

requestScreenCapture();
while(1){
领金豆()
查金豆抽奖()

注销登陆()
}
//launchApp("电信营业厅");
//sleep(1000)
function 领金豆(){
    sleep(5000)
    click(988,1777);
    sleep(1000)
    while(!click("领流量"));
id("ivCusButton").findOne().click();
for(let i=0;i<4;i++){
  while(!click("新浪微博"));
text("图文分享").findOne()
while(!click("取消"));  
}
while(!click("微信好友"));
text("多选").findOne()
back()
text("分享有礼").findOne()
var  每日分享=text ("每日分享得20金豆").findOne(1000)
sleep(2000)
while(!text("微信好友").findOne(100)){
    
    swipe(900, 900, 200, 200, 300)
sleep(1000)
swipe(900, 900, 200, 200, 300)

swipe(900, 900, 200, 200, 300)

swipe(900, 900, 200, 200, 300)
swipe(900, 900, 200, 200, 300)

swipe(900, 900, 200, 200, 300)
sleep(1000)
   每日分享=text ("每日分享得20金豆").findOne(1000)
   
  if(每日分享){
      sleep(2000)
      log("找到每日分享")
click(每日分享.bounds().centerX()+560,每日分享.bounds().centerY()+100)
      }
    }
 
while(!click("微信好友"));
text("多选").findOne()
sleep(1000)
back()
sleep(2000)
var  每日分享=text ("每日分享得20金豆").findOne(1000)
  if(每日分享){
      sleep(2000)
      log("找到每日分享")
click(每日分享.bounds().centerX()+560,每日分享.bounds().centerY()+100)
      }
while(!click("微信好友"));
text("多选").findOne()
sleep(1000)
back()

sleep(5000)
back()
}
function 查金豆抽奖(){
    while(1){
    if(text ("我的云盘").findOne(100)){
        console.log("进入抽奖页面");
     click("我的金豆");
     sleep(2000)
    }
    if(text ("活动太火爆了，过会儿再来~").findOne(100)){
        back()
        }
    if(text ("抽奖每次消耗 20 金豆").findOne(100)){
        sleep(1000)
        var 金豆数量= textEndsWith ("个").findOne().text()
        log(金豆数量)
       金豆数量= 金豆数量.split("个")[0]
       log(金豆数量)
       金豆数量=金豆数量.split("豆")[1]
        log(金豆数量*1)
   if(金豆数量*1<200){
    console.log(金豆数量+"金豆数量小于200抽奖");
    className("android.view.View").clickable(true).depth(8).findOne().click()
    text("继续抽奖").findOne(4000)
    if(text ("我知道了").findOne(1000)){
        back()
        sleep(1000)
        break
    }
    back()
   }else{
    console.log("金豆数量大于200抽奖");
    app.startActivity({
        action: "android.intent.action.VIEW",
        data: "ctclient://startapp/android/open?LinkType=5&Link=https%3A%2F%2Fwapact.189.cn%3A9001%2FturnTable%2FturnTable_index.html%3Fticket%3D%24ticket%24%26activityId%3D60cc578e4f7abf4717109f24",
        packageName: "com.ct.client"
    });
    
    className("android.view.View").clickable(true).findOne().click()
    while(!text ("关闭").findOne(100)){
        
       if( text ("995折充值").findOne(1000)){
          app.startActivity({
        action: "android.intent.action.VIEW",
        data: "ctclient://startapp/android/open?LinkType=5&Link=https%3A%2F%2Fwapact.189.cn%3A9001%2FturnTable%2FturnTable_index.html%3Fticket%3D%24ticket%24%26activityId%3D60cc578e4f7abf4717109f24",
        packageName: "com.ct.client"
    });
    
           }
        click(520,1231);
        }
    back()
    break
   }
       }  
   
    }
   
  
}
function 注销登陆(){
   id("ivSet").findOne().click()
    id("rlCommon").findOne().click()
    id("rlCancel").findOne().click()
    id("btnClear").findOne().click()
    id("tvLogin").findOne().click()
    sleep(5000)
    id("rvBindlist").findOne().children().forEach(child => {
        var target = child.findOne(id("tvTitle"));
        target.click();
        });
        click(354,489)
}